package com.yang.doctorrecruitment.action;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.UserResumeDAO;
import com.yang.doctorrecruitment.dto.BaseInfomation;
import com.yang.doctorrecruitment.dto.JobIntension;
import com.yang.doctorrecruitment.utils.NullChange;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class BaseInfomationAction extends ActionSupport {
    //这里有很多属性，不同类别的信息如何处理，首先采用单个信息封装成类，添加单个信息的get set即可，测试一下
   public BaseInfomation baseinfomation;

    public BaseInfomation getBaseinfomation() {
        return baseinfomation;
    }

    public void setBaseinfomation(BaseInfomation baseinfomation) {
        this.baseinfomation = baseinfomation;
    }

    //基本信息执行的action
    public String BaseInfo(){
        //拿到了数据，开始保存数据,先转换成json,应当考虑用户没有保存相关信息，依然可以保存
        String Name= NullChange.NullChange(baseinfomation.getName());
        int Sex=baseinfomation.getSex();
        String Address= NullChange.NullChange(baseinfomation.getAddress());
        String Birth= NullChange.NullChange(baseinfomation.getBirth());
        String Email= NullChange.NullChange(baseinfomation.getEmail());
        String TelPhone= NullChange.NullChange(baseinfomation.getTelPhone());
        //进行存储,先转换成json
        JSONObject json=new JSONObject();
        json.put("Name",Name);
        json.put("Sex",Sex);
        json.put("Address",Address);
        json.put("Birth",Birth);
        json.put("Email",Email);
        json.put("TelPhone",TelPhone);
        String jsonString =json.toJSONString();
        //需要拿到UserID
        ActionContext ac=ActionContext.getContext();
        Map session=ac.getSession();
        String UserID= (String) session.get("UserID");
        boolean res= UserResumeDAO.updataBaseinfo(jsonString,UserID);
        HttpServletRequest request= (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
        if(res){

            request.setAttribute("tipMessage",1);
            return SUCCESS;
        }else{
            request.setAttribute("tipMessage",2);
            return ERROR;
        }





    }







}
